package com.pass.util.dialog;

import android.view.View;
import android.widget.CheckBox;
import android.widget.DatePicker;
import android.widget.TextView;

import com.pass.util.R;

import java.util.Date;

public class PureDatePickerDialog extends BaseDialogFragment {
    private DatePicker datePicker;

    private TextView cancelBtn;
    private TextView okBtn;
    private DateCallback callback;
    private String sureStr;
    private String cancelStr;
    private int initYear;
    private int initMonth;
    private int initDay;


    public PureDatePickerDialog(int initYear, int initMonth, int initDay, DateCallback dialogCallback) {
        super(DialogPosition.CENTER, false);
        this.sureStr = "确定";
        this.cancelStr = "取消";
        this.callback = dialogCallback;
        this.initYear = initYear;
        this.initMonth = initMonth;
        this.initDay = initDay;
    }


    @Override
    protected int getLayoutId() {
        return R.layout.dlg_pure_timepicker;
    }

    @Override
    protected int getDialogStyleId() {
        return R.style.MyDialogStyle;
    }

    @Override
    protected void initView(View rootView) {
        datePicker = rootView.findViewById(R.id.date_picker);
        datePicker.init(initYear, initMonth, initDay, null);
        cancelBtn = rootView.findViewById(R.id.tv_cancel);
        okBtn = rootView.findViewById(R.id.tv_ok);
        datePicker.setCalendarViewShown(false);
    }

    @Override
    protected void initData() {
        cancelBtn.setText(cancelStr);
        okBtn.setText(sureStr);

    }

    @Override
    protected void initListener() {
        okBtn.setOnClickListener(v -> {
            if (null != callback) {
                String dateStr = String.format("%d-%d-%d", datePicker.getYear(), datePicker.getMonth() + 1, datePicker.getDayOfMonth());
                callback.onOKClicked(dateStr);
            }
            dismiss();
        });
        cancelBtn.setOnClickListener(v -> {
            if (null != callback) {
                callback.onCancelled();
            }
            dismiss();
        });
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

}
